package cn.tedu.egmybatis10.controller;

import cn.tedu.egmybatis10.mapper.UserMapper;
import cn.tedu.egmybatis10.pojo.entity.User;
import cn.tedu.egmybatis10.pojo.vo.UserListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/v1/users/")
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @RequestMapping("insert")
    public String insert(User user){
        user.setCreated(new Date());

        userMapper.insert(user);
        return "添加成功";
    }

    @RequestMapping("userList")
    public List<UserListVO> select(){
        return userMapper.select();
    }

    @RequestMapping("delete")
    public String delete(Integer id){
        userMapper.delete(id);
        return "删除成功";
    }

    @RequestMapping("update")
    public String update(User user){
        userMapper.update(user);
        return "更新成功";
    }
}
